package com.zhang.shopcar.base;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Handler;

import com.zhang.shopcar.entity.ProductInfo;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class MyApplication extends Application {

    public static Context mContext;
    private static Handler mHandler;
    private static long mMainThreadId;

    public static boolean isSelectLocationCity() {
        return isSelectLocationCity;
    }


    public static void setIsSelectLocationCity(boolean isSelectLocationCity) {
        MyApplication.isSelectLocationCity = isSelectLocationCity;
    }

    private static boolean isSelectLocationCity;
    private static List<Activity> mActivtiyList;



    private static Map<Long, Integer> mGoodsMap;//提交订单是保存的map，通过id保存数量
    private static Map<Long, Integer> mGoodsSharesMap;//提交订单是保存的map，通过id保存是否购买股票商品
    private static Map<String, Integer> mShopMap;
    private static Map<String, String> mRemarkMap;
    private static Map<Integer, String> mHistoryMap;
    private static Map<String, String> mCityMap;
    private static List<String> mHistoryList;
    private static List<String> mCityList;
    public static List<ProductInfo> mStockAttriList;

    private static DecimalFormat mDf;

    public static List<Activity> getMyListActivity() {
        return mActivtiyList;
    }

    public static Map<Long, Integer> getGoodsMap() {
        return mGoodsMap;
    } public static Map<Long, Integer> getmGoodsSharesMap() {
        return mGoodsSharesMap;
    }

    public static Map<String, Integer> getShopMap() {
        return mShopMap;
    }

    public static Map<String, String> getRemarkMap() {
        return mRemarkMap;
    }

    public static Map<Integer, String> getHistoryMap() {
        return mHistoryMap;
    }

    public static List<String> getHistoryList() {
        return mHistoryList;
    }

    public static List<String> getCityList() {
        return mCityList;
    }

    public static Map<String, String> getCityMap() {
        return mCityMap;
    }



    //库存商品添加的集合
    public static List<ProductInfo> getStockAttriList() {
        return mStockAttriList;
    }
/*public static String getLocationCity(){
    return mLocationCity;
}*/




    /**
     * 得到上下文
     */
    public static Context getContext() {
        return mContext;
    }


    /**
     * 得到主线程的handler
     */
    public static Handler getHandler() {
        return mHandler;
    }


    public static DecimalFormat getDecimalFormat() {
        return mDf;
    }


    /**
     * 得到主线程的线程id
     */


    public static long getMainThreadId() {
        return mMainThreadId;
    }

    public static void exit() {

        for (Activity activity : mActivtiyList) {
            activity.finish();
        }


    }

    @Override
    public void onCreate() {// 程序的入口方法
        mDf = new DecimalFormat("#0.00");

        mRemarkMap = new HashMap<>();//留言map
        mShopMap = new HashMap<>();//商家id,map
        mHistoryMap = new HashMap<>();//历史访问城市
        mCityMap = new HashMap<>();//历史访问城市
        mGoodsMap = new HashMap<>(); //商品goodsOnlineDetailsId  和 数量
        mGoodsSharesMap = new HashMap<>(); //商品goodsOnlineDetailsId  和 是否购买股票商品
        mHistoryList = new ArrayList<>();
        mCityList = new ArrayList<>();
        isSelectLocationCity = false;
        /*--------------- 创建应用里面需要用到的一些共有的属性 ---------------*/
        // 1.上下文
        mContext = getApplicationContext();

        // 2.主线程handler
        mHandler = new Handler();

        // 3.主线程的id
        mMainThreadId = android.os.Process.myTid();
        /**
         * Tid: thread
         * Pid: process
         * Uid: user
         */

        // mOkHttpClient   = new OkHttpClient();
        //    Picasso.setSingletonInstance(new Picasso.Builder(mContext).downloader(new OkHttpDownloader(getUnsafeOkHttpClient())).build());


        super.onCreate();
    }

/*
 public static OkHttpClient getUnsafeOkHttpClient() {

        try {
            // Create a trust manager that does not validate certificate chains
            final TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
                @Override
                public void checkClientTrusted(
                        java.security.cert.X509Certificate[] chain,
                        String authType) throws CertificateException {
                }

                @Override
                public void checkServerTrusted(
                        java.security.cert.X509Certificate[] chain,
                        String authType) throws CertificateException {
                }

                @Override
                public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                    return null;
                }
            }};

            // Install the all-trusting trust manager
            final SSLContext sslContext = SSLContext.getInstance("SSL");
            sslContext.init(null, trustAllCerts,
                    new java.security.SecureRandom());
            // Create an ssl socket factory with our all-trusting manager
            final SSLSocketFactory sslSocketFactory = sslContext
                    .getSocketFactory();

            OkHttpClient okHttpClient = new OkHttpClient();
            okHttpClient.setSslSocketFactory(sslSocketFactory);
            okHttpClient.setHostnameVerifier(new HostnameVerifier() {

                @Override
                public boolean verify(String hostname, SSLSession session) {
                    return true;

                }
            });

            return okHttpClient;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }
*/

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
    }
}
